package com.bmd.backgroundmanger.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.bmd.backgroundmanger.entity.UserFavorite;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 用户收藏Mapper接口
 */
@Mapper
public interface UserFavoriteMapper extends BaseMapper<UserFavorite> {

    /**
     * 根据用户ID查询收藏的题目（包含题目信息）
     */
    List<UserFavorite> selectFavoritesByUserId(Integer userId);

    /**
     * 检查用户是否已收藏某题目
     */
    @Select("SELECT COUNT(*) FROM user_favorites WHERE user_id = #{userId} AND question_id = #{questionId}")
    Integer checkFavoriteExists(Integer userId, Integer questionId);
} 